﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties.CApSLPSetLocationsPropertiesCommonPropertiesUtils
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using C1.Win.C1FlexGrid.Util.BaseControls;
using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Olp;
using Tecnomatix.Engineering.Olp.RoboticParameters;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui48;


namespace DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties;

internal class CApSLPSetLocationsPropertiesCommonPropertiesUtils
{
  private TxFlexGrid _txFGCommonPropertiesList;
  private TxOlpRoboticParametersManager _roboticManager;
  private CApSLPSetLocationsPropertiesResetMechanism _resetMechanism;
  private TxObjectList _locations;
  private int _lastRowEditedInExternalDialog = -1;
  private bool _userEditMode = true;
  private bool _didUserCancelAction;
  private PauseLocationsEventsNotifications _pauseLocationsNotifications;
  private ResumeLocationsEventsNotifications _resumeLocationsNotifications;
  private TxOlpMotionCommandServices _motionServices;
  private CCUiSLPSetLocationsPropertiesPickObjectDlg _pickObjectDlg;
  private Dictionary<string, string> _filteredPropertiesNames = new Dictionary<string, string>();
  private CApSLPRobotParamToMfgAttributeMapping _relinkManager;
  private List<CUiSLPGridHostedCtrl> _hostedControls;
  private ImageList _gridImages;
  private ToolTip _tooltip = new ToolTip();
  private int _RELINK_COLUMN_AUTOSIZED_WIDTH = -1;
  private Dictionary<string, Dictionary<string, object>> _originalPropertyToLocationValuesCache = new Dictionary<string, Dictionary<string, object>>(500);
  private TxPerformanceModeEx _operationRoboticParametersUpdateMode = new TxPerformanceModeEx((TxPerformanceModeType) 7);
  private bool _isInOperationRoboticParametersUpdateMode;
  private bool _hasChangesDuringRoboticParametersUpdateMode;
  private RefreshCommonPropertiesListDueToEvent _operationRoboticParametersUpdateMode_CommonRefreshCallback;
  private RefreshCommonPropertiesListDueToEvent _operationRoboticParametersUpdateMode_SourceRefreshCallback;
  private Dictionary<string, LocationPropertyExtendedInfo> _propertyIdToExtendedInfoMap = new Dictionary<string, LocationPropertyExtendedInfo>();
  private Dictionary<string, string> _propertyNiceNameToIdMap = new Dictionary<string, string>();
  private const string _CUSTOMIZED_MOTION = "Customized Motion";
  private const string _CONFIGURATION = "General_Configuration";
  private const string _EXTERNAL_AXES_VALUES = "General_External Axes Values";
  private const string _MOTION_ZONE = "Motion_Zone";
  private const string _RELINK_COLUMN_NAME = "Re-link";
  private const string _RELINK_COLUMN_DISABLED_STYLE = "Re-link_DisabledStyle";
  private const string _RELINK_HOSTED_BTN_IMAGE = "MultiEditingInPathEditor.SetLocationsProperties.Resources.RelinkSmall.ico";
  private const int _RELINK_COLUMN_MIN_WIDTH = 17;
  private const string _VALUE_COLUMN_ITALIC_STYLE = "Value_ItalicStyle";
  private const string _VALUE_COLUMN_DISABLED_ITALIC_STYLE = "Value_DisabledItalicStyle";

  public CApSLPSetLocationsPropertiesCommonPropertiesUtils(
    TxFlexGrid commonProperties,
    TxObjectList locations,
    TxOlpRoboticParametersManager roboticManager,
    PauseLocationsEventsNotifications pauseLocationsNotifications,
    ResumeLocationsEventsNotifications resumeLocationsNotifications)
  {
    this._txFGCommonPropertiesList = commonProperties;
    this._roboticManager = roboticManager;
    this._resetMechanism = new CApSLPSetLocationsPropertiesResetMechanism();
    this._locations = locations;
    this._pauseLocationsNotifications = pauseLocationsNotifications;
    this._resumeLocationsNotifications = resumeLocationsNotifications;
    this._relinkManager = new CApSLPRobotParamToMfgAttributeMapping();
    this._relinkManager.RoboticOperations = this._locations;
    this._hostedControls = new List<CUiSLPGridHostedCtrl>();
    this.RegisterEvents();
  }

  public void InitializeList()
  {
    this.AddCustomGridStyles();
    this.CreateCommonPropertiesStructure();
    this._resetMechanism.Clear();
  }

  private void CreateCommonPropertiesStructure()
  {
    ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols[0].Name = ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols[0].Caption = StringTable.ResourceManager.GetString("SLP_CommonListPropertyTitle");
    ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols[1].Name = ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols[1].Caption = StringTable.ResourceManager.GetString("SLP_CommonListValueTitle");
    this.AddRelinkColumn();
  }

  private void AddCustomGridStyles()
  {
    ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles.Add("Re-link_DisabledStyle", ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"]).DataType = typeof (object);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles.Add("Value_ItalicStyle", ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles.Normal).Font = new Font(((C1FlexGridBase) this._txFGCommonPropertiesList).Styles.Normal.Font, FontStyle.Italic);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles.Add("Value_DisabledItalicStyle", ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"]).Font = new Font(((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"].Font, FontStyle.Italic);
  }

  public void RegisterEvents()
  {
    ((C1FlexGridBase) this._txFGCommonPropertiesList).CellButtonClick += new RowColEventHandler(this._txFGCommonPropertiesList_CellButtonClick);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).StartEdit += new RowColEventHandler(this._txFGCommonPropertiesList_StartEdit);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).AfterEdit += new RowColEventHandler(this._txFGCommonPropertiesList_AfterEdit);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).SetupEditor += new RowColEventHandler(this._txFGCommonPropertiesList_SetupEditor);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).KeyUpEdit += new KeyEditEventHandler(this._txFGCommonPropertiesList_KeyUpEdit);
    ((Control) this._txFGCommonPropertiesList).Paint += new PaintEventHandler(this._txFGCommonPropertiesList_Paint);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).AfterResizeColumn += new RowColEventHandler(this._txFGCommonPropertiesList_AfterResizeColumn);
    ((Control) this._txFGCommonPropertiesList).Resize += new EventHandler(this._txFGCommonPropertiesList_Resize);
    TxApplicationEx.PerformanceModeManager().ModeBegin += new TxPerformanceModeManagerEx_ModeBeginEventHandler(this.CApSLPSetLocationsPropertiesCommonPropertiesUtils_ModeBegin);
    TxApplicationEx.PerformanceModeManager().ModeEnd += new TxPerformanceModeManagerEx_ModeEndEventHandler(this.CApSLPSetLocationsPropertiesCommonPropertiesUtils_ModeEnd);
  }

  public void UnRegisterEvents()
  {
    ((C1FlexGridBase) this._txFGCommonPropertiesList).CellButtonClick -= new RowColEventHandler(this._txFGCommonPropertiesList_CellButtonClick);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).StartEdit -= new RowColEventHandler(this._txFGCommonPropertiesList_StartEdit);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).AfterEdit -= new RowColEventHandler(this._txFGCommonPropertiesList_AfterEdit);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).SetupEditor -= new RowColEventHandler(this._txFGCommonPropertiesList_SetupEditor);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).KeyUpEdit -= new KeyEditEventHandler(this._txFGCommonPropertiesList_KeyUpEdit);
    ((Control) this._txFGCommonPropertiesList).Paint -= new PaintEventHandler(this._txFGCommonPropertiesList_Paint);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).AfterResizeColumn -= new RowColEventHandler(this._txFGCommonPropertiesList_AfterResizeColumn);
    ((Control) this._txFGCommonPropertiesList).Resize -= new EventHandler(this._txFGCommonPropertiesList_Resize);
    TxApplicationEx.PerformanceModeManager().ModeBegin -= new TxPerformanceModeManagerEx_ModeBeginEventHandler(this.CApSLPSetLocationsPropertiesCommonPropertiesUtils_ModeBegin);
    TxApplicationEx.PerformanceModeManager().ModeEnd -= new TxPerformanceModeManagerEx_ModeEndEventHandler(this.CApSLPSetLocationsPropertiesCommonPropertiesUtils_ModeEnd);
  }

  public void FillCommonPropertiesWithContent(TxObjectList locations)
  {
    this._locations = locations;
    this._relinkManager.RoboticOperations = this._locations;
    this._userEditMode = false;
    ((ScrollableControl) this._txFGCommonPropertiesList).BeginUpdate();
    TxPathEditorToDotNetGap editorToDotNetGap = (TxPathEditorToDotNetGap) null;
    List<string> failedPropertyNames = new List<string>(0);
    try
    {
      editorToDotNetGap = new TxPathEditorToDotNetGap();
      editorToDotNetGap.StartCacheMode();
      this.ClearList();
      this._filteredPropertiesNames.Clear();
      if (this._locations != null && ((Collection<ITxObject>) this._locations).Count > 0)
      {
        foreach (KeyValuePair<string, string> property in this._roboticManager.GetProperties())
        {
          if (!this.FillRowContent(property, (Row) null))
            failedPropertyNames.Add(property.Value);
        }
      }
      this.UpdateRelinkColumnVisibility();
    }
    finally
    {
      editorToDotNetGap?.EndCacheMode();
      GC.KeepAlive((object) editorToDotNetGap);
      ((ScrollableControl) this._txFGCommonPropertiesList).EndUpdate();
      this.UpdateRelinkColumnWidth();
      this._userEditMode = true;
      if (failedPropertyNames.Count > 0)
        this.ShowErrorForPropertiesRead(failedPropertyNames);
    }
  }

  private bool FillRowContent(KeyValuePair<string, string> propertyName, Row newRow)
  {
    bool flag1 = true;
    bool flag2 = false;
    bool flag3 = false;
    bool flag4 = true;
    object obj1 = (object) null;
    List<string> stringList = (List<string>) null;
    string str = string.Empty;
    bool flag5 = false;
    bool flag6 = propertyName.Key.Contains("Customized Motion");
    bool flag7 = propertyName.Key.Contains("General_Configuration");
    bool flag8 = propertyName.Key.Contains("General_External Axes Values");
    TxOlpDataValueBase dataValue = this._roboticManager.GetDataValue(propertyName.Key);
    foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) this._locations)
    {
      flag4 = CApSLPSetLocationsPropertiesLogic.IsPropertyValidOnLocation(propertyName.Key, location);
      if (flag4)
      {
        if (!flag5)
        {
          flag5 = true;
          if (!this._filteredPropertiesNames.ContainsKey(propertyName.Key))
            this._filteredPropertiesNames.Add(propertyName.Key, propertyName.Value);
        }
        try
        {
          if (!flag2)
          {
            if (flag6)
            {
              obj1 = (object) dataValue.ToString((ITxOperation) location);
            }
            else
            {
              obj1 = dataValue.GetValue((ITxOperation) location);
              this.CacheOriginalValue(propertyName.Key, (ITxLocationOperation) location, obj1);
            }
            flag2 = true;
            flag3 = true;
            switch (dataValue)
            {
              case TxOlpDataValueList _:
                stringList = (dataValue as TxOlpDataValueList).Items;
                continue;
              case TxOlpDataValueListEnum _:
                stringList = (dataValue as TxOlpDataValueListEnum).Items;
                continue;
              case TxOlpDataValueObject _:
                str = "...";
                continue;
              case TxOlpDataValueString _:
                if (flag6 | flag7 | flag8)
                {
                  str = "...";
                  continue;
                }
                continue;
              default:
                continue;
            }
          }
          else
          {
            object obj2 = dataValue.GetValue((ITxOperation) location);
            this.CacheOriginalValue(propertyName.Key, (ITxLocationOperation) location, obj2);
            if (!CApSLPSetLocationsPropertiesLogic.AreEqual(obj1, obj2))
              flag3 = false;
            if (dataValue is TxOlpDataValueList)
              stringList = CApSLPSetLocationsPropertiesLogic.IntersectLists(stringList, (dataValue as TxOlpDataValueList).Items);
            else if (dataValue is TxOlpDataValueListEnum)
              stringList = CApSLPSetLocationsPropertiesLogic.IntersectLists(stringList, (dataValue as TxOlpDataValueListEnum).Items);
          }
        }
        catch (Exception ex)
        {
          flag1 = false;
        }
      }
      else
        break;
    }
    if (flag4)
    {
      if (stringList != null)
        str = stringList.Count <= 0 ? "|" : CApSLPSetLocationsPropertiesLogic.GetListAsString(stringList, "|");
      if (newRow == null)
        newRow = ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows.Add();
      if (!flag2)
        obj1 = (object) null;
      if (!flag3)
        obj1 = (object) StringTable.ResourceManager.GetString("SLP_MultipleValues");
      if (obj1 is ITxObject)
        obj1 = (object) (obj1 as ITxObject).Name;
      else if (obj1 != null)
        obj1 = (object) obj1.ToString();
      TxAccessType accessType = this._roboticManager.GetAccessType(propertyName.Key);
      if (accessType == 1 || accessType == null || accessType == 4 && !flag6 || propertyName.Key.Contains("Motion_Zone") && this.AreAllLocationsOfTypeWeld())
      {
        if (accessType == 4 && dataValue is TxOlpDataValueString && !this.IsExplicitlyExcludedForEdit(propertyName.Key))
        {
          ((RowCol) newRow).ComboList = "...";
          ((RowCol) newRow).AllowEditing = true;
          this.AddPropertyExtendedInfo(propertyName.Key, new LocationPropertyExtendedInfo()
          {
            NiceName = propertyName.Value,
            AccessType = accessType,
            IsComplex = true,
            CanCopy = false,
            CanReset = false
          });
        }
        else
        {
          ((C1FlexGridBase) this._txFGCommonPropertiesList).SetCellStyle(((RowCol) newRow).Index, 0, ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"]);
          ((C1FlexGridBase) this._txFGCommonPropertiesList).SetCellStyle(((RowCol) newRow).Index, 1, ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"]);
          ((RowCol) newRow).AllowEditing = false;
        }
      }
      else if (!string.IsNullOrEmpty(str))
      {
        if (str == "|")
        {
          ((C1FlexGridBase) this._txFGCommonPropertiesList).SetCellStyle(((RowCol) newRow).Index, 0, ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"]);
          ((C1FlexGridBase) this._txFGCommonPropertiesList).SetCellStyle(((RowCol) newRow).Index, 1, ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"]);
          ((RowCol) newRow).AllowEditing = false;
        }
        else
          ((RowCol) newRow).ComboList = str;
      }
      newRow[0] = (object) propertyName.Value;
      object fixedValue = (object) null;
      string displayFormat = string.Empty;
      Type valueType = this._roboticManager.GetValueType(propertyName.Key);
      CApSLPSetLocationsPropertiesLogic.GetRowFormat(propertyName.Key, obj1, this._roboticManager.GetUnitType(propertyName.Key), out displayFormat, out fixedValue);
      ((RowCol) newRow).DataType = typeof (object);
      newRow[1] = fixedValue;
      if (!string.IsNullOrEmpty(displayFormat))
        ((RowCol) newRow).Format = displayFormat;
      if (valueType != (Type) null)
        ((RowCol) newRow).DataType = valueType;
      ((RowCol) newRow).Style.TextAlign = (TextAlignEnum) 1;
      Column relinkColumn = this.GetRelinkColumn();
      if (relinkColumn != null)
      {
        bool flag9 = this.ContainsRelinkInfo(((RowCol) newRow).Index);
        if (!flag9)
        {
          string propertyHardcodedId = this._roboticManager.GetPropertyHardcodedId(propertyName.Key);
          if (!string.IsNullOrEmpty(propertyHardcodedId) && this.IsRelinkableParameter(propertyHardcodedId))
          {
            this.AddHostedControl(CApSLPSetLocationsPropertiesCommonPropertiesUtils.eHostedCtrlType.Relink, ((RowCol) newRow).Index, ((RowCol) relinkColumn).Index);
            this.SetHardcodedParameterIdToRelinkInfo(((RowCol) newRow).Index, propertyHardcodedId);
            flag9 = true;
          }
        }
        if (flag9)
          this.UpdateValueStyleUsingRelinkInfo(((RowCol) newRow).Index);
        this.UpdateRelinkCellStyle(((RowCol) newRow).Index);
      }
    }
    GC.KeepAlive((object) dataValue);
    return flag1;
  }

  private void ClearList()
  {
    this._tooltip.RemoveAll();
    this.RemoveHostedControls();
    this.ClearRelinkInfo();
    if (((RowColCollection) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows).Count <= 1)
      return;
    ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows.RemoveRange(1, ((RowColCollection) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows).Count - 1);
  }

  public bool HasField(string nameOfField)
  {
    bool flag = false;
    if (this._txFGCommonPropertiesList != null)
    {
      foreach (Row row in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows)
      {
        if (row[0].ToString() == nameOfField)
        {
          flag = true;
          break;
        }
      }
    }
    return flag;
  }

  public bool IsFieldReadOnly(string nameOfField)
  {
    bool flag = true;
    if (this._txFGCommonPropertiesList != null)
    {
      foreach (Row row in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows)
      {
        if (row[0].ToString() == nameOfField)
        {
          flag = !((RowCol) row).AllowEditing;
          break;
        }
      }
    }
    return flag;
  }

  public bool IsFieldBlockedForCopy(string nameOfField)
  {
    return this._propertyNiceNameToIdMap.ContainsKey(nameOfField) && this.IsBlockedForCopy(this._propertyNiceNameToIdMap[nameOfField]);
  }

  public Dictionary<string, string> GetFilteredPropertiesNames() => this._filteredPropertiesNames;

  private CUiSLPGridHostedCtrl AddHostedControl(
    CApSLPSetLocationsPropertiesCommonPropertiesUtils.eHostedCtrlType ctrlType,
    int row,
    int col)
  {
    CUiSLPGridHostedCtrl hostedCtrl = (CUiSLPGridHostedCtrl) null;
    if (ctrlType != CApSLPSetLocationsPropertiesCommonPropertiesUtils.eHostedCtrlType.None && ctrlType == CApSLPSetLocationsPropertiesCommonPropertiesUtils.eHostedCtrlType.Relink)
    {
      Control relinkControl = this.CreateRelinkControl();
      if (relinkControl != null)
      {
        hostedCtrl = new CUiSLPGridHostedCtrl((C1.Win.C1FlexGrid.C1FlexGrid) this._txFGCommonPropertiesList, ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows[row], ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols[col]);
        hostedCtrl.AttachControl(relinkControl, this.GetHostedControlNextTabIndex(), true, CUiSLPGridHostedCtrl.CtrlPositionInCellStyle.MiddleCenter);
      }
    }
    if (hostedCtrl != null)
    {
      this._hostedControls.Add(hostedCtrl);
      this.RegisterForEvents(hostedCtrl);
    }
    return hostedCtrl;
  }

  private void RemoveHostedControls()
  {
    foreach (CUiSLPGridHostedCtrl hostedControl in this._hostedControls)
    {
      this.UnregisterForEvents(hostedControl);
      hostedControl.DetachControl();
    }
    this._hostedControls.Clear();
  }

  private void RegisterForEvents(CUiSLPGridHostedCtrl hostedCtrl)
  {
    hostedCtrl.Click += new EventHandler(this.hostedCtrl_Click);
  }

  private void UnregisterForEvents(CUiSLPGridHostedCtrl hostedCtrl)
  {
    hostedCtrl.Click -= new EventHandler(this.hostedCtrl_Click);
  }

  private int GetHostedControlNextTabIndex()
  {
    int controlNextTabIndex = ((Control) this._txFGCommonPropertiesList).TabIndex + 1;
    if (this._hostedControls.Count > 0)
      controlNextTabIndex = this._hostedControls[this._hostedControls.Count - 1].TabIndex + 1;
    return controlNextTabIndex;
  }

  private void hostedCtrl_Click(object sender, EventArgs e)
  {
    if (!(sender is CUiSLPGridHostedCtrl slpGridHostedCtrl) || !(slpGridHostedCtrl.Column.Name == "Re-link"))
      return;
    this.RelinkControlClicked(((RowCol) slpGridHostedCtrl.Row).Index);
  }

  private ImageList GridImages
  {
    get
    {
      if (this._gridImages == null)
      {
        this._gridImages = new ImageList();
        this._gridImages.ColorDepth = ColorDepth.Depth24Bit;
        this._gridImages.ImageSize = new Size(16 /*0x10*/, 16 /*0x10*/);
        this._gridImages.TransparentColor = Color.Transparent;
      }
      return this._gridImages;
    }
  }

  private Image GetGridImage(string assemblyRelativePathName)
  {
    Image gridImage = (Image) null;
    if (this.GridImages.Images.ContainsKey(assemblyRelativePathName))
    {
      gridImage = this.GridImages.Images[assemblyRelativePathName];
    }
    else
    {
      Icon icon = this.LoadIcon(assemblyRelativePathName);
      if (icon != null)
      {
        this.GridImages.Images.Add(assemblyRelativePathName, icon);
        gridImage = this.GridImages.Images[assemblyRelativePathName];
      }
    }
    return gridImage;
  }

  private Icon LoadIcon(string assemblyRelativePathName)
  {
    Icon icon = (Icon) null;
    try
    {
      Assembly assembly = this.GetType().Assembly;
      icon = new Icon(assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{assemblyRelativePathName}"));
    }
    catch (Exception ex)
    {
    }
    return icon;
  }

  private void AddRelinkColumn()
  {
    if (this.GetRelinkColumn() != null)
      return;
    ((ScrollableControl) this._txFGCommonPropertiesList).BeginUpdate();
    Column column = ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols.Add();
    column.Name = "Re-link";
    column.Caption = StringTable.ResourceManager.GetString("SLP_CommonListRelinkColumnTitle");
    ((RowCol) column).DataType = typeof (object);
    ((RowCol) column).ImageAlign = (ImageAlignEnum) 4;
    ((RowCol) column).AllowDragging = false;
    ((RowCol) column).AllowEditing = false;
    column.AllowFiltering = (AllowFiltering) 4;
    ((RowCol) column).AllowMerging = false;
    column.AllowSorting = false;
    bool extendLastCol = ((C1FlexGridBase) this._txFGCommonPropertiesList).ExtendLastCol;
    ((C1FlexGridBase) this._txFGCommonPropertiesList).ExtendLastCol = false;
    ((C1FlexGridBase) this._txFGCommonPropertiesList).AutoSizeCols(((RowCol) column).Index, ((RowCol) column).Index, 0);
    this._RELINK_COLUMN_AUTOSIZED_WIDTH = column.WidthDisplay;
    ((C1FlexGridBase) this._txFGCommonPropertiesList).ExtendLastCol = extendLastCol;
    if (this._RELINK_COLUMN_AUTOSIZED_WIDTH < 17)
      this._RELINK_COLUMN_AUTOSIZED_WIDTH = 17;
    ((ScrollableControl) this._txFGCommonPropertiesList).EndUpdate();
  }

  private Column GetRelinkColumn()
  {
    Column relinkColumn = (Column) null;
    if (((C1FlexGridBase) this._txFGCommonPropertiesList).Cols.Contains("Re-link"))
      relinkColumn = ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols["Re-link"];
    return relinkColumn;
  }

  private void UpdateRelinkColumnVisibility()
  {
    Column relinkColumn = this.GetRelinkColumn();
    if (relinkColumn == null)
      return;
    bool flag = false;
    foreach (RowCol row in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows)
    {
      if (this.ContainsRelinkInfo(row.Index))
      {
        flag = true;
        break;
      }
    }
    ((RowCol) relinkColumn).Visible = flag;
  }

  private void UpdateRelinkColumnWidth()
  {
    Column relinkColumn = this.GetRelinkColumn();
    if (relinkColumn == null || !((RowCol) relinkColumn).Visible)
      return;
    int num1 = 6;
    int num2 = 16 /*0x10*/;
    switch (((ScrollableControl) this._txFGCommonPropertiesList).ScrollBarsVisible)
    {
      case ScrollBars.Horizontal:
        num1 += 4;
        break;
      case ScrollBars.Vertical:
        num1 += num2;
        break;
      case ScrollBars.Both:
        num1 += num2;
        break;
    }
    int columnAutosizedWidth = this._RELINK_COLUMN_AUTOSIZED_WIDTH;
    int num3 = ((Control) this._txFGCommonPropertiesList).Width - columnAutosizedWidth - num1;
    int num4 = 0;
    foreach (Column col in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols)
    {
      if (((RowCol) col).Index != ((RowCol) relinkColumn).Index)
        num4 += col.WidthDisplay;
    }
    ((ScrollableControl) this._txFGCommonPropertiesList).BeginUpdate();
    ((C1FlexGridBase) this._txFGCommonPropertiesList).Cols[1].WidthDisplay += num3 - num4;
    relinkColumn.WidthDisplay = columnAutosizedWidth;
    ((ScrollableControl) this._txFGCommonPropertiesList).EndUpdate();
  }

  private bool IsRelinkableParameter(string roboticParamHardcodedId)
  {
    bool flag = false;
    if (!string.IsNullOrEmpty(roboticParamHardcodedId))
      flag = this._relinkManager.CanConnectParameterForSomeOperation(roboticParamHardcodedId);
    return flag;
  }

  private bool IsDisconnectedRelinkableParameter(string roboticParamHardcodedId)
  {
    bool flag = false;
    if (!string.IsNullOrEmpty(roboticParamHardcodedId))
      flag = this._relinkManager.IsDisconnectedParameterForSomeOperation(roboticParamHardcodedId);
    return flag;
  }

  private Control CreateRelinkControl()
  {
    TxButton relinkControl = new TxButton();
    ((Control) relinkControl).Size = new Size(16 /*0x10*/, 16 /*0x10*/);
    ((Control) relinkControl).Text = "";
    relinkControl.SetImage(TxImageManager.GetImageByKey("Relink"), new Size());
    ((ButtonBase) relinkControl).ImageAlign = ContentAlignment.MiddleCenter;
    ((Control) relinkControl).Enabled = true;
    ((ButtonBase) relinkControl).FlatStyle = FlatStyle.Flat;
    ((ButtonBase) relinkControl).FlatAppearance.BorderSize = 0;
    this._tooltip.SetToolTip((Control) relinkControl, StringTable.ResourceManager.GetString("SLP_RelinkBtnTooltip"));
    return (Control) relinkControl;
  }

  private void RelinkControlClicked(int row)
  {
    string idFromRelinkInfo = this.GetHardcodedParameterIdFromRelinkInfo(row);
    if (idFromRelinkInfo == null)
      return;
    string propertyId = this._roboticManager.GetPropertyId(((C1FlexGridBase) this._txFGCommonPropertiesList)[row, 0].ToString());
    this.SaveOldValue(propertyId);
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this.PauseLocationsNotifications();
    this._relinkManager.ConnectParameter(idFromRelinkInfo);
    this.ResumeLocationsNotifications();
    this.RefreshChangedRows(row, propertyId);
    Cursor.Current = current;
  }

  private bool ContainsRelinkInfo()
  {
    bool flag = false;
    if (this.GetRelinkColumn() != null)
    {
      foreach (RowCol row in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows)
      {
        if (this.ContainsRelinkInfo(row.Index))
        {
          flag = true;
          break;
        }
      }
    }
    return flag;
  }

  private bool ContainsRelinkInfo(int row) => this.GetRelinkInfo(row) != null;

  private void ClearRelinkInfo()
  {
    if (this.GetRelinkColumn() == null)
      return;
    foreach (Row row in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows)
    {
      if (this.ContainsRelinkInfo(((RowCol) row).Index))
        this.ClearRelinkInfo(((RowCol) row).Index);
    }
  }

  private void ClearRelinkInfo(int row) => this.SetRelinkInfo(row, (object) null);

  private object GetRelinkInfo(int row)
  {
    object relinkInfo = (object) null;
    Column relinkColumn = this.GetRelinkColumn();
    if (relinkColumn != null)
      relinkInfo = ((C1FlexGridBase) this._txFGCommonPropertiesList).GetUserData(row, ((RowCol) relinkColumn).Index);
    return relinkInfo;
  }

  private bool SetRelinkInfo(int row, object info)
  {
    bool flag = false;
    Column relinkColumn = this.GetRelinkColumn();
    if (relinkColumn != null)
    {
      ((C1FlexGridBase) this._txFGCommonPropertiesList).SetUserData(row, ((RowCol) relinkColumn).Index, info);
      flag = true;
    }
    return flag;
  }

  private void SetHardcodedParameterIdToRelinkInfo(int row, string hardcodedParamId)
  {
    this.SetRelinkInfo(row, (object) hardcodedParamId);
  }

  private string GetHardcodedParameterIdFromRelinkInfo(int row)
  {
    string idFromRelinkInfo = (string) null;
    object relinkInfo = this.GetRelinkInfo(row);
    if (relinkInfo != null)
      idFromRelinkInfo = relinkInfo as string;
    return idFromRelinkInfo;
  }

  private void UpdateRelinkCellStyle(int row)
  {
    Column relinkColumn = this.GetRelinkColumn();
    if (relinkColumn == null)
      return;
    CellStyle cellStyle = (CellStyle) null;
    if (!this.ContainsRelinkInfo(row))
      cellStyle = ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["Re-link_DisabledStyle"];
    ((C1FlexGridBase) this._txFGCommonPropertiesList).SetCellStyle(row, ((RowCol) relinkColumn).Index, cellStyle);
  }

  private void UpdateValueStyleUsingRelinkInfo(int row)
  {
    if (!this.ContainsRelinkInfo(row))
      return;
    bool allowEditing = ((RowCol) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows[row]).AllowEditing;
    bool flag = false;
    if (this.IsDisconnectedRelinkableParameter(this.GetHardcodedParameterIdFromRelinkInfo(row)))
      flag = true;
    CellStyle cellStyle = !flag ? (!allowEditing ? ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["ReadOnly"] : (CellStyle) null) : (!allowEditing ? ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["Value_DisabledItalicStyle"] : ((C1FlexGridBase) this._txFGCommonPropertiesList).Styles["Value_ItalicStyle"]);
    ((C1FlexGridBase) this._txFGCommonPropertiesList).SetCellStyle(row, 1, cellStyle);
  }

  private void _txFGCommonPropertiesList_CellButtonClick(object sender, RowColEventArgs e)
  {
    if (this._locations == null || ((Collection<ITxObject>) this._locations).Count <= 0)
      return;
    this._lastRowEditedInExternalDialog = e.Row;
    string propertyId = this._roboticManager.GetPropertyId(((C1FlexGridBase) this._txFGCommonPropertiesList)[this._lastRowEditedInExternalDialog, 0].ToString());
    this.SaveOldValueForPropertyAndDependencies(propertyId);
    LocationPropertyExtendedInfo propertyExtendedInfo = this.GetPropertyExtendedInfo(propertyId);
    this._roboticManager.GetDataValue(propertyId);
    if (propertyId.Contains("Customized Motion"))
    {
      if (CApSLPSetLocationsPropertiesLogic.AreAllLocationsOfTheSameProcessType(this._locations))
      {
        this._motionServices = new TxOlpMotionCommandServices(new TxOlpControllerUtilities().GetRobot(((Collection<ITxObject>) this._locations)[0] as ITxOperation));
        this._motionServices.ExternalWindowClosedEventHandler = new EventHandler(this.CustomizedMotionWindow_Closed);
        List<ITxRoboticOperation> roboticOperationList = new List<ITxRoboticOperation>();
        for (int index = 0; index < ((Collection<ITxObject>) this._locations).Count; ++index)
          roboticOperationList.Add(((Collection<ITxObject>) this._locations)[index] as ITxRoboticOperation);
        CApSLPSetLocationsPropertiesLocationsListUtils.m_shouldFireParamEvents = false;
        this._motionServices.OpenMotionDialog(roboticOperationList);
      }
      else
      {
        int num = (int) TxMessageBox.Show(StringTable.ResourceManager.GetString("SLP_ProcessType_Error"), StringTable.ResourceManager.GetString("SLP_ProcessType_Error_Title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
    }
    else if (propertyId.Contains("General_Configuration"))
    {
      if (!TxApplication.CommandsManager.ExecuteCommand("RobotAndDevice.RobotConfiguration"))
        return;
      this.RefreshChangedRows(this._lastRowEditedInExternalDialog, propertyId);
    }
    else if (propertyId.Contains("General_External Axes Values"))
    {
      if (!TxApplication.CommandsManager.ExecuteCommand("RobotAndDevice.SetExternalAxesValues"))
        return;
      this.RefreshChangedRows(this._lastRowEditedInExternalDialog, propertyId);
    }
    else if (propertyExtendedInfo != null && propertyExtendedInfo.IsComplex && propertyExtendedInfo.AccessType == 4)
    {
      string str = propertyId.Remove(0, propertyId.IndexOf('_') + 1);
      ITxOlpRobotControllerParametersHandler parametersHandlerInstance = new TxOlpControllerUtilities().InitAndGetRobotControllerParametersHandlerInstance((ITxOperation) (((Collection<ITxObject>) this._locations)[0] as ITxRoboticLocationOperation));
      TxObjectList<ITxOperation> txObjectList = new TxObjectList<ITxOperation>();
      foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) this._locations)
        ((Collection<ITxOperation>) txObjectList).Add((ITxOperation) location);
      this.PauseLocationsNotifications();
      TxApplication.ActiveUndoManager.StartTransaction();
      TxApplicationEx.PerformanceModeManager().BeginMode(this._operationRoboticParametersUpdateMode);
      try
      {
        if (((Collection<ITxOperation>) txObjectList).Count == 1)
          parametersHandlerInstance.EditComplex(str, ((Collection<ITxOperation>) txObjectList)[0]);
        else
          parametersHandlerInstance.EditComplex(str, txObjectList);
      }
      catch (Exception ex)
      {
      }
      finally
      {
        TxApplicationEx.PerformanceModeManager().EndMode(this._operationRoboticParametersUpdateMode);
        this.RefreshChangedRows(this._lastRowEditedInExternalDialog, propertyId);
        TxApplication.ActiveUndoManager.EndTransaction();
        this.ResumeLocationsNotifications();
      }
    }
    else
    {
      object obj = (object) null;
      ITxObject preSelectedObject = (ITxObject) null;
      if (((C1FlexGridBase) this._txFGCommonPropertiesList)[this._lastRowEditedInExternalDialog, 1] != (object) StringTable.ResourceManager.GetString("SLP_MultipleValues") && ((C1FlexGridBase) this._txFGCommonPropertiesList)[this._lastRowEditedInExternalDialog, 1] != null)
        obj = this._roboticManager.GetValue(propertyId, ((Collection<ITxObject>) this._locations)[0] as ITxOperation);
      if (obj is ITxObject)
        preSelectedObject = obj as ITxObject;
      this.OpenPickObjectDlg(this._roboticManager.GetTypeFilter(propertyId), propertyId, preSelectedObject);
    }
  }

  private void OpenPickObjectDlg(
    TxTypeFilter typeFilter,
    string propertyID,
    ITxObject preSelectedObject)
  {
    this.CloseChildForms();
    this._pickObjectDlg = new CCUiSLPSetLocationsPropertiesPickObjectDlg(typeFilter, propertyID, preSelectedObject);
    ((Form) this._pickObjectDlg).FormClosing += new FormClosingEventHandler(this.pickObjectDlg_FormClosing);
    ((Control) this._pickObjectDlg).Show();
  }

  public void CloseChildForms()
  {
    if (this._pickObjectDlg == null)
      return;
    ((Form) this._pickObjectDlg).FormClosing -= new FormClosingEventHandler(this.pickObjectDlg_FormClosing);
    ((Form) this._pickObjectDlg).Close();
    this._pickObjectDlg = (CCUiSLPSetLocationsPropertiesPickObjectDlg) null;
  }

  private void pickObjectDlg_FormClosing(object sender, FormClosingEventArgs e)
  {
    if (!(sender is CCUiSLPSetLocationsPropertiesPickObjectDlg) || (sender as CCUiSLPSetLocationsPropertiesPickObjectDlg).DlgResult != DialogResult.OK)
      return;
    this.ChangeValue((sender as CCUiSLPSetLocationsPropertiesPickObjectDlg).PropertyID, (object) (sender as CCUiSLPSetLocationsPropertiesPickObjectDlg).PickedObject);
    this.RefreshChangedRows(this._lastRowEditedInExternalDialog, (sender as CCUiSLPSetLocationsPropertiesPickObjectDlg).PropertyID);
  }

  private void CustomizedMotionWindow_Closed(object sender, EventArgs e)
  {
    if (this._motionServices != null && this._motionServices.DialogResult == DialogResult.OK && this._locations != null && ((Collection<ITxObject>) this._locations).Count > 0)
    {
      Cursor current = Cursor.Current;
      Cursor.Current = Cursors.WaitCursor;
      TxApplicationEx.FreezeDisplay();
      string propertyId = this._roboticManager.GetPropertyId(((C1FlexGridBase) this._txFGCommonPropertiesList)[this._lastRowEditedInExternalDialog, 0].ToString());
      this.CopyValue(propertyId, ((Collection<ITxObject>) this._locations)[0] as ITxRoboticLocationOperation);
      if (propertyId.Contains("Customized Motion"))
      {
        List<ITxOperation> itxOperationList = new List<ITxOperation>();
        for (int index = 0; index < ((Collection<ITxObject>) this._locations).Count; ++index)
        {
          if (((Collection<ITxObject>) this._locations)[index] is ITxOperation)
            itxOperationList.Add(((Collection<ITxObject>) this._locations)[index] as ITxOperation);
        }
        if (itxOperationList.Count > 1)
          this._motionServices.SetOtherLocationsParameters(itxOperationList);
      }
      TxApplicationEx.UnfreezeDisplay();
      TxApplication.RefreshDisplay();
      CApSLPSetLocationsPropertiesLocationsListUtils.m_shouldFireParamEvents = true;
      CApSLPSetLocationsPropertiesLocationsListUtils.Refresh();
      this.RefreshChangedRows(this._lastRowEditedInExternalDialog, propertyId);
      Cursor.Current = current;
    }
    CApSLPSetLocationsPropertiesLocationsListUtils.m_shouldFireParamEvents = true;
  }

  private void _txFGCommonPropertiesList_AfterEdit(object sender, RowColEventArgs e)
  {
    if (!this._userEditMode)
      return;
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    string propertyId = this._roboticManager.GetPropertyId(((C1FlexGridBase) this._txFGCommonPropertiesList)[e.Row, 0].ToString());
    bool flag = !TxApplicationEx.PerformanceModeManager().InMode(this._operationRoboticParametersUpdateMode);
    TxOlpControllerUtilities controllerUtilities = (TxOlpControllerUtilities) null;
    try
    {
      if (flag)
        TxApplicationEx.PerformanceModeManager().BeginMode(this._operationRoboticParametersUpdateMode);
      controllerUtilities = new TxOlpControllerUtilities();
      controllerUtilities.StartCacheMode();
      if (!this._didUserCancelAction)
      {
        this._roboticManager.GetUnitType(propertyId);
        object commonProperties = ((C1FlexGridBase) this._txFGCommonPropertiesList)[e.Row, 1];
        if (commonProperties != null)
        {
          object basicFormat = CApSLPSetLocationsPropertiesLogic.GetBasicFormat(propertyId, (object) commonProperties.ToString().Trim(), this._roboticManager.GetUnitType(propertyId));
          this.ChangeValue(propertyId, basicFormat);
        }
      }
      else
        ((RowCol) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows[e.Row]).Clear((ClearFlags) 2);
      this.RefreshChangedRows(e.Row, propertyId);
    }
    finally
    {
      controllerUtilities?.EndCacheMode();
      if (flag)
        TxApplicationEx.PerformanceModeManager().EndMode(this._operationRoboticParametersUpdateMode);
    }
    Cursor.Current = current;
  }

  private void _txFGCommonPropertiesList_StartEdit(object sender, RowColEventArgs e)
  {
    if (!this._userEditMode || ((C1FlexGridBase) sender).Clip.EndsWith("..."))
      return;
    this.SaveOldValueForPropertyAndDependencies(this._roboticManager.GetPropertyId(((C1FlexGridBase) this._txFGCommonPropertiesList)[e.Row, 0].ToString()));
  }

  private void SaveOldValueForPropertyAndDependencies(string propertyId)
  {
    if (this.IsBlockedForReset(propertyId))
      return;
    TxOlpControllerUtilities controllerUtilities = (TxOlpControllerUtilities) null;
    try
    {
      controllerUtilities = new TxOlpControllerUtilities();
      controllerUtilities.StartCacheMode();
      this.SaveOldValue(propertyId);
      foreach (string dependentPropertiesId in this._roboticManager.GetDependentPropertiesIds(propertyId))
        this.SaveOldValue(dependentPropertiesId);
    }
    finally
    {
      controllerUtilities?.EndCacheMode();
    }
  }

  private void _txFGCommonPropertiesList_KeyUpEdit(object sender, KeyEditEventArgs e)
  {
    if (e.KeyCode == Keys.Return)
      ((C1FlexGridBase) this._txFGCommonPropertiesList).FinishEditing();
    this._didUserCancelAction = false;
  }

  private void _txFGCommonPropertiesList_SetupEditor(object sender, RowColEventArgs e)
  {
    if (((C1FlexGridBase) this._txFGCommonPropertiesList).Editor == null || !(((C1FlexGridBase) this._txFGCommonPropertiesList).Editor is TextBox editor))
      return;
    editor.MouseDown += new MouseEventHandler(this.cellTextBox_MouseDown);
  }

  private void _txFGCommonPropertiesList_Paint(object sender, PaintEventArgs e)
  {
    if (this._hostedControls == null || this._hostedControls.Count <= 0)
      return;
    foreach (CUiSLPGridHostedCtrl hostedControl in this._hostedControls)
    {
      if (((RowCol) hostedControl.Row).Visible && ((RowCol) hostedControl.Column).Visible)
        hostedControl.UpdatePosition();
      else
        hostedControl.Visible = false;
    }
  }

  private void _txFGCommonPropertiesList_AfterResizeColumn(object sender, RowColEventArgs e)
  {
    this.UpdateRelinkColumnWidth();
  }

  private void _txFGCommonPropertiesList_Resize(object sender, EventArgs e)
  {
    this.UpdateRelinkColumnWidth();
  }

  private void cellTextBox_MouseDown(object sender, MouseEventArgs e)
  {
    if (!(sender is TextBox textBox))
      return;
    textBox.MouseDown -= new MouseEventHandler(this.cellTextBox_MouseDown);
    textBox.SelectAll();
    this._didUserCancelAction = true;
  }

  private void RefreshChangedRows(int rowIndex, string propertyId)
  {
    List<string> failedPropertyNames = new List<string>(0);
    KeyValuePair<string, string> propertyName1 = new KeyValuePair<string, string>(propertyId, ((C1FlexGridBase) this._txFGCommonPropertiesList)[rowIndex, 0].ToString());
    if (!this.FillRowContent(propertyName1, ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows[rowIndex]))
      failedPropertyNames.Add(propertyName1.Value);
    foreach (string dependentPropertiesId in this._roboticManager.GetDependentPropertiesIds(propertyId))
    {
      int rowIndex1 = this.GetRowIndex(dependentPropertiesId);
      if (rowIndex1 >= 0)
      {
        KeyValuePair<string, string> propertyName2 = new KeyValuePair<string, string>(dependentPropertiesId, ((C1FlexGridBase) this._txFGCommonPropertiesList)[rowIndex1, 0].ToString());
        if (!this.FillRowContent(propertyName2, ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows[rowIndex1]))
          failedPropertyNames.Add(propertyName2.Value);
      }
    }
    if (failedPropertyNames.Count <= 0)
      return;
    this.ShowErrorForPropertiesRead(failedPropertyNames);
  }

  private void PauseLocationsNotifications() => this._pauseLocationsNotifications();

  private void ResumeLocationsNotifications() => this._resumeLocationsNotifications();

  private void CApSLPSetLocationsPropertiesCommonPropertiesUtils_ModeBegin(
    object sender,
    TxPerformanceModeManagerEx_ModeEventArgs args)
  {
    if (args.Mode.Mode != 7)
      return;
    this.OnOperationRoboticParametersUpdateModeStarted();
  }

  private void CApSLPSetLocationsPropertiesCommonPropertiesUtils_ModeEnd(
    object sender,
    TxPerformanceModeManagerEx_ModeEventArgs args)
  {
    if (args.Mode.Mode != 7)
      return;
    this.OnOperationRoboticParametersUpdateModeEnded();
  }

  public void SaveOldValue(string propertyId)
  {
    if (string.IsNullOrEmpty(propertyId) || this.IsBlockedForReset(propertyId))
      return;
    foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) this._locations)
    {
      if (!this._resetMechanism.HasOldValue(location, propertyId))
      {
        object oldValue = this.GetOriginalValueFromCache(propertyId, (ITxLocationOperation) location) ?? this._roboticManager.GetValue(propertyId, (ITxOperation) location);
        this._resetMechanism.SetOldValue(location, propertyId, oldValue);
      }
    }
  }

  private void ChangeValue(string propertyId, object newValue)
  {
    this.PauseLocationsNotifications();
    TxApplication.ActiveUndoManager.StartTransaction();
    TxApplicationEx.PerformanceModeManager().BeginMode(this._operationRoboticParametersUpdateMode);
    if (newValue is string && newValue.ToString().EndsWith("...") && ((Collection<ITxObject>) this._locations).Count > 0)
    {
      string str = propertyId.Remove(0, propertyId.IndexOf('_') + 1);
      ITxOlpRobotControllerParametersHandler parametersHandlerInstance = new TxOlpControllerUtilities().InitAndGetRobotControllerParametersHandlerInstance((ITxOperation) (((Collection<ITxObject>) this._locations)[0] as ITxRoboticLocationOperation));
      TxObjectList<ITxOperation> txObjectList = new TxObjectList<ITxOperation>();
      foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) this._locations)
        ((Collection<ITxOperation>) txObjectList).Add((ITxOperation) location);
      parametersHandlerInstance.OnComplexValueChanged(str, newValue.ToString(), txObjectList);
      foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) this._locations)
      {
        string complexRepresentation = parametersHandlerInstance.GetComplexRepresentation(str, (ITxOperation) location, (TxOlpCommandLayerRepresentation) 2);
        this._roboticManager.SetValue(propertyId, (ITxOperation) location, (object) complexRepresentation);
      }
    }
    else
    {
      object basicFormat = CApSLPSetLocationsPropertiesLogic.GetBasicFormat(propertyId, newValue, this._roboticManager.GetUnitType(propertyId));
      if (!string.IsNullOrEmpty(propertyId))
      {
        foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) this._locations)
        {
          this._resetMechanism.SetNewValue(location, propertyId, basicFormat);
          this._roboticManager.SetValue(propertyId, (ITxOperation) location, basicFormat);
        }
      }
    }
    TxApplicationEx.PerformanceModeManager().EndMode(this._operationRoboticParametersUpdateMode);
    TxApplication.ActiveUndoManager.EndTransaction();
    this.ResumeLocationsNotifications();
  }

  private void CopyValue(string propertyId, ITxRoboticLocationOperation sourceLocation)
  {
    this.PauseLocationsNotifications();
    bool flag = TxApplicationEx.PerformanceModeManager().InMode(this._operationRoboticParametersUpdateMode);
    if (!flag)
      TxApplicationEx.PerformanceModeManager().BeginMode(this._operationRoboticParametersUpdateMode);
    if (!string.IsNullOrEmpty(propertyId))
    {
      foreach (string dependentPropertiesId in this._roboticManager.GetDependentPropertiesIds(propertyId))
        this.SaveOldValue(dependentPropertiesId);
      object newValue = this._roboticManager.GetValue(propertyId, (ITxOperation) sourceLocation);
      foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) this._locations)
      {
        if (propertyId.Contains("General_External Axes Values"))
          newValue = (object) sourceLocation.RobotExternalAxesData;
        else if (propertyId.Contains("General_Configuration"))
          newValue = (object) sourceLocation.RobotConfigurationData;
        this._resetMechanism.SetNewValue(location, propertyId, newValue);
        this._roboticManager.CopyValue(propertyId, (ITxOperation) location, (ITxOperation) sourceLocation);
      }
    }
    if (!flag)
      TxApplicationEx.PerformanceModeManager().EndMode(this._operationRoboticParametersUpdateMode);
    this.ResumeLocationsNotifications();
  }

  private int GetRowIndex(string propertyId)
  {
    int rowIndex = -1;
    foreach (Row row in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows)
    {
      if (this._roboticManager.GetPropertyId(row[0].ToString()) == propertyId)
      {
        rowIndex = ((RowCol) row).Index;
        break;
      }
    }
    return rowIndex;
  }

  private bool AreAllLocationsOfTypeWeld()
  {
    bool flag = true;
    foreach (ITxObject location in (Collection<ITxObject>) this._locations)
    {
      if (!(location is TxWeldLocationOperation))
      {
        flag = false;
        break;
      }
    }
    return flag;
  }

  public void Reset(TxObjectList locations)
  {
    this.PauseLocationsNotifications();
    TxApplication.ActiveUndoManager.StartTransaction();
    TxApplicationEx.PerformanceModeManager().BeginMode(this._operationRoboticParametersUpdateMode);
    foreach (ITxRoboticLocationOperation location in (Collection<ITxObject>) locations)
    {
      Dictionary<string, object> allOriginalValues = this._resetMechanism.GetAllOriginalValues(location);
      if (allOriginalValues != null)
      {
        foreach (KeyValuePair<string, object> keyValuePair in allOriginalValues)
          this._roboticManager.SetValue(keyValuePair.Key, (ITxOperation) location, keyValuePair.Value, true);
      }
    }
    this._resetMechanism.Clear();
    TxApplicationEx.PerformanceModeManager().EndMode(this._operationRoboticParametersUpdateMode);
    TxApplication.ActiveUndoManager.EndTransaction();
    this.FillCommonPropertiesWithContent(locations);
    this.ResumeLocationsNotifications();
  }

  public void Copy(ITxRoboticLocationOperation sourceLocation, List<string> listOfPropertiesToCopy)
  {
    TxApplication.ActiveUndoManager.StartTransaction();
    TxApplicationEx.PerformanceModeManager().BeginMode(this._operationRoboticParametersUpdateMode);
    if (listOfPropertiesToCopy != null && listOfPropertiesToCopy.Count > 0)
    {
      Dictionary<string, string> properties = this._roboticManager.GetProperties();
      foreach (string str in listOfPropertiesToCopy)
      {
        bool flag = false;
        if (properties.ContainsKey(str) && this._txFGCommonPropertiesList != null && !this.IsBlockedForCopy(str))
        {
          foreach (Row row in (IEnumerable) ((C1FlexGridBase) this._txFGCommonPropertiesList).Rows)
          {
            if (row[0].ToString() == properties[str])
            {
              flag = ((RowCol) row).AllowEditing;
              if (row[0].ToString() == "Config")
              {
                flag = true;
                break;
              }
              break;
            }
          }
        }
        if (flag)
        {
          this.SaveOldValue(str);
          this.CopyValue(str, sourceLocation);
        }
      }
    }
    TxApplicationEx.PerformanceModeManager().EndMode(this._operationRoboticParametersUpdateMode);
    TxApplication.ActiveUndoManager.EndTransaction();
  }

  public void SaveOldValueForProperty(string propertyId)
  {
    this.SaveOldValue(propertyId);
    foreach (string dependentPropertiesId in this._roboticManager.GetDependentPropertiesIds(propertyId))
      this.SaveOldValue(dependentPropertiesId);
  }

  private void CacheOriginalValue(string propertyId, ITxLocationOperation location, object value)
  {
    Dictionary<string, object> dictionary;
    if (!this._originalPropertyToLocationValuesCache.TryGetValue(propertyId, out dictionary))
    {
      this._originalPropertyToLocationValuesCache.Add(propertyId, new Dictionary<string, object>(this._locations != null ? ((Collection<ITxObject>) this._locations).Count : 1)
      {
        {
          ((ITxObject) location).Id,
          value
        }
      });
    }
    else
    {
      if (dictionary == null)
        return;
      string id = ((ITxObject) location).Id;
      if (dictionary.ContainsKey(id))
        return;
      dictionary.Add(id, value);
    }
  }

  private object GetOriginalValueFromCache(string propertyId, ITxLocationOperation location)
  {
    Dictionary<string, object> dictionary;
    object obj;
    return this._originalPropertyToLocationValuesCache.TryGetValue(propertyId, out dictionary) && dictionary.TryGetValue(((ITxObject) location).Id, out obj) ? obj : (object) null;
  }

  public bool IsInOperationRoboticParametersUpdateMode
  {
    get => this._isInOperationRoboticParametersUpdateMode;
    private set => this._isInOperationRoboticParametersUpdateMode = value;
  }

  public bool HasChangesDuringRoboticParametersUpdateMode
  {
    get => this._hasChangesDuringRoboticParametersUpdateMode;
    set => this._hasChangesDuringRoboticParametersUpdateMode = value;
  }

  public RefreshCommonPropertiesListDueToEvent OperationRoboticParametersUpdateMode_CommonRefreshCallback
  {
    get => this._operationRoboticParametersUpdateMode_CommonRefreshCallback;
    set => this._operationRoboticParametersUpdateMode_CommonRefreshCallback = value;
  }

  public RefreshCommonPropertiesListDueToEvent OperationRoboticParametersUpdateMode_SourceRefreshCallback
  {
    get => this._operationRoboticParametersUpdateMode_SourceRefreshCallback;
    set => this._operationRoboticParametersUpdateMode_SourceRefreshCallback = value;
  }

  private void OnOperationRoboticParametersUpdateModeStarted()
  {
    this._isInOperationRoboticParametersUpdateMode = true;
    this._hasChangesDuringRoboticParametersUpdateMode = false;
    this._operationRoboticParametersUpdateMode_CommonRefreshCallback = (RefreshCommonPropertiesListDueToEvent) null;
    this._operationRoboticParametersUpdateMode_SourceRefreshCallback = (RefreshCommonPropertiesListDueToEvent) null;
  }

  private void OnOperationRoboticParametersUpdateModeEnded()
  {
    this._isInOperationRoboticParametersUpdateMode = false;
    if (this._hasChangesDuringRoboticParametersUpdateMode)
    {
      this._hasChangesDuringRoboticParametersUpdateMode = false;
      if (this._operationRoboticParametersUpdateMode_CommonRefreshCallback != null)
        this._operationRoboticParametersUpdateMode_CommonRefreshCallback();
      if (this._operationRoboticParametersUpdateMode_SourceRefreshCallback != null)
        this._operationRoboticParametersUpdateMode_SourceRefreshCallback();
    }
    this._operationRoboticParametersUpdateMode_CommonRefreshCallback = (RefreshCommonPropertiesListDueToEvent) null;
    this._operationRoboticParametersUpdateMode_SourceRefreshCallback = (RefreshCommonPropertiesListDueToEvent) null;
  }

  public LocationPropertyExtendedInfo GetPropertyExtendedInfo(string propertyId)
  {
    return this._propertyIdToExtendedInfoMap.ContainsKey(propertyId) ? this._propertyIdToExtendedInfoMap[propertyId] : (LocationPropertyExtendedInfo) null;
  }

  public void AddPropertyExtendedInfo(string propertyId, LocationPropertyExtendedInfo extendedInfo)
  {
    if (this._propertyIdToExtendedInfoMap.ContainsKey(propertyId))
      return;
    this._propertyIdToExtendedInfoMap.Add(propertyId, extendedInfo);
    if (this._propertyNiceNameToIdMap.ContainsKey(extendedInfo.NiceName))
      return;
    this._propertyNiceNameToIdMap.Add(extendedInfo.NiceName, propertyId);
  }

  public bool IsBlockedForCopy(string propertyId)
  {
    LocationPropertyExtendedInfo propertyExtendedInfo = this.GetPropertyExtendedInfo(propertyId);
    return propertyExtendedInfo != null && !propertyExtendedInfo.CanCopy;
  }

  public bool IsBlockedForReset(string propertyId)
  {
    LocationPropertyExtendedInfo propertyExtendedInfo = this.GetPropertyExtendedInfo(propertyId);
    return propertyExtendedInfo != null && !propertyExtendedInfo.CanReset;
  }

  public bool IsExplicitlyExcludedForEdit(string propertyId)
  {
    return propertyId.EndsWith("Config") || propertyId.Contains("Olp Commands");
  }

  private void ShowErrorForPropertiesRead(List<string> failedPropertyNames)
  {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.AppendLine(StringTable.SLP_MSG_COMMON_FAILED_PROPERTIES_READ);
    bool flag = true;
    foreach (string failedPropertyName in failedPropertyNames)
    {
      if (flag)
        flag = false;
      else
        stringBuilder.Append(", ");
      stringBuilder.Append(failedPropertyName);
    }
    int num = (int) TxDoNotShowAgainMessageBox.Show(stringBuilder.ToString(), StringTable.SET_LOCATIONS_PROPERTIES_NAME, "SLP_MSG_COMMON_FAILED_PROPERTIES_READ", MessageBoxButtons.OK, MessageBoxIcon.Hand, DialogResult.OK);
  }

  private enum eHostedCtrlType
  {
    None,
    Relink,
  }
}
